#include "MyString.h"
#include<string.h>


void InitMyString(MyStr *s)
{
   s->len=0; 
   memset(s->str,0,Size);//给以str首地址内存每个值都为0

}
//替换原来的字符串
void InsertStr(MyStr *s,const char *newStr)
{   
    int slen=strlen(newStr);
    s->len=Size-1>slen?slen:Size-1;
    strncpy(s->str,newStr,s->len);
}
//在原字符串上继续插入新字符串
void AppendStr(MyStr *s, const char *newStr)
{
       strncat(s->str,newStr,Size-1-s->len);
       s->len=strlen(s->str);
}

//在原字符串上移除字符串
void RemoveString(MyStr *s,const char *str)
{
  char *dest=strstr(s->str,str);
  while(dest!=NULL)
  {
    char *back=dest+strlen(str);
    while(*back!='\0')
        *dest++=*back++;
    *dest='\0';
    dest=strstr(s->str,str);
  }
  s->len=strlen(s->str);

}
//打印字符串
void PrintStr(MyStr *s, bool HaveEnter)
{
    if(HaveEnter)
         printf("%s\n",s->str);
    else
         printf("%s",s->str);
}
//判读字符串相等

bool IsStrEqual(MyStr *s, MyStr *str)
{
    return strcmp(s->str,str->str)==0;
}

char *GetSptr(MyStr *s)
{
    return s->str;
}
//安全读取字符串
void GetStr(MyStr *s)
{
    InitMyString(s);
    char c=0;
    //读到回车结束
    while((c=getchar())!='\n'&&s->len<Size-1)
    {
        s->str[s->len++]=c;
    }
    printf("%d\n",s->len);
 
}